package com.llkj.contractmanagement.contractmanagement.login;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;

import com.llkj.contractmanagement.main.BaseActivity;
import com.llkj.contractmanagement.main.MainActivity;
import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.model.UserInfoBean;


/**
 * 启动页
 * Created by zhy.px on 2016/3/11.
 */
public class WelcomeActivity extends BaseActivity implements Animation.AnimationListener {
    private LinearLayout ll_welcome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_welcome;
    }

    private void init() {
        ll_welcome = (LinearLayout) findViewById(R.id.ll_welcome);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f);
        alphaAnimation.setDuration(3000);
        alphaAnimation.setAnimationListener(this);
        ll_welcome.setAnimation(alphaAnimation);
    }


    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        isFirst();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }

    /**
     * 是否第一次打开app
     */
    private void isFirst() {
        Intent intent = null;
//        if (!UserInfoBean.getInstance().isFirstOpen()) {
//            UserInfoBean.getInstance().setFirstOpen(true);
//            UserInfoBean.save(this);
//            intent = new Intent(this, GuidePageActivity.class);
//            startActivity(intent);
//        } else {
//            if (UserInfoBean.getInstance(this).isLogin()) {
//                intent = new Intent(this, MainActivity.class);
//                startActivity(intent);
//            } else {
//                intent = new Intent(this, LoginActivity.class);
//                startActivity(intent);
//            }
//        }

        if (UserInfoBean.getInstance().isLogin()) {
            intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        } else {
            intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
        }
        this.finish();
    }

}
